-- deflect_damage
-- created by zhuangsl
-- 抵挡并反射伤害

return {
    apply = function(prop, baseValue)
        return math.modf(baseValue * prop[3] / 1000);
    end,

    -- 受创触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 反射的伤害,至少1点
        local deflectDamage = math.modf(arg * prop[3] / 1000 );
        deflectDamage = math.max(deflectDamage, 1);

        -- 只持续受创的回合，需要将持续时间变成受创的回合
        local arr = who.dbase:queryTemp("prop", "special", {});

        -- 先把所有的special清空
        PropM.deleteProp(who, "special");

        local special = {};
        for _, p in pairs(arr) do
            if p[1] == prop[1] then
                -- 如果是反射伤害的属性，持续回合变更为本回合
                p[4] = CombatM.getRound();
            end
            table.insert(special, p);
        end

        if #special > 0 then
            PorpM.multiRecord(target, special, "special");
        end

        return deflectDamage;
    end,

    record = function(target, prop, path)
        return false;
    end
};
